//扩展app中的think对象

const Validator = require('fastest-validator');
module.exports = {
    //数据验证
    validate(data, rules) {
        let v = new Validator();
        return v.validate(data, rules);
    },
    //字符串到json
    stringToJson(string) {
        try {
            if (string.length < 2) return false;
            return JSON.parse(string);
        } catch (e) {
            return false;
        }
    },
    //当前时间错
    nowTimestamp() {
        return (Date.parse(new Date())) / 1000;
    },
    //是否在数据里面
    in_array(array, val) {
        for (let i = 0; i < array.length; i++) {
            if (array[i] === val) return true;
        }
        return false;
    }
};